package com.demo.tf;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.demo.model.ReplyInfo;

public class ReplyItemAdapter extends BaseAdapter {

	private Context context;
	private List<ReplyInfo> list;
	public ReplyItemAdapter(Context ct,List<ReplyInfo> list){
		this.context = ct;
		this.list = list;
	}
	
	public int getCount() {
		return list.size();
	}
	
	public Object getItem(int position) {
		if (position < list.size()) {
			return list.get(position);
		}
		else{
			return null;
		}
	}

	public long getItemId(int position) {
		if (position < list.size()){
			return list.get(position).getRId();
		}
		else {
			return -1;
		}
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = LayoutInflater.from(context).inflate(R.layout.reply_item, null);
		ViewHolder holder = new ViewHolder();

		holder.userIcon = (ImageView) convertView.findViewById(R.id.reply_item_user_icon);
		holder.userName = (TextView) convertView.findViewById(R.id.reply_item_user_name);
		holder.replyTime = (TextView) convertView.findViewById(R.id.reply_item_time);
		holder.replyContent = (TextView) convertView.findViewById(R.id.reply_item_content);
		
		ReplyInfo rInfo = list.get(position);
		if(rInfo!=null){
			convertView.setTag(rInfo.getRId());
			holder.userIcon.setBackgroundColor(Color.GREEN);
			holder.userName.setText(rInfo.getUName());
			holder.replyTime.setText(rInfo.getDate());
			holder.replyContent.setText(rInfo.getContent());
		}
		
		return convertView;
	}
		
	private static class ViewHolder{
		ImageView userIcon;
		TextView userName;
		TextView replyContent;
		TextView replyTime;
	}
}
